import { compareAsc, distanceInWordsToNow } from 'date-fns';
import zh_cn from 'date-fns/locale/zh_cn';

/**
 * 距离现在的时间
 * @param compare_time 需要比较的时间戳
 * @example distance_now(compare_time);
 */
export default function distance_now(compare_time: number) {
	const flag = compareAsc(new Date(), compare_time);
	// todo (2.0版本不能出现前和后)
	if (flag === 0) {
		return distanceInWordsToNow(compare_time, { locale: zh_cn });
	} else if (flag === 1) {
		return distanceInWordsToNow(compare_time, { locale: zh_cn }) + '前';
	} else {
		return distanceInWordsToNow(compare_time, { locale: zh_cn }) + '后';
	}
}
